package SV_UMC_THREADS;

public class Example {
    public class SV_UMC_THREADS_Sample_1 extends HttpServlet {
        public void doPost(HttpServletRequest request,
                           HttpServletResponse response) throws IOException,
                ServletException {
            doProcessRequest(request, response);
        }
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response) throws IOException,
                ServletException {
            doProcessRequest(request, response);
        }
        private void doProcessRequest(HttpServletRequest request,
                                      HttpServletResponse response) throws IOException,
                ServletException {
            final StringBuffer buffer = new StringBuffer();
            Runnable r = new Runnable() {
                public void run() {
                    buffer.append("Processing...\n");
                    // do something
                    buffer.append("Finished.\n");
                }
            };
            Thread t = new Thread(r);
            t.start();
            // do something else, then get results from background thread
            try {
                t.join();
            } catch (InterruptedException e) {
            }
            String log = buffer.toString();
            // create page...
        }
    }

}
